'use strict'

let http = require('http');

let fs = require('fs');

let dirPath = 'MYAPP'
// const { readdir } = require('node:fs');
function readDir(dirfather) {
    http.createServer((req, res) => {
        fs.readdir(dirfather, (err, data) => {
            if (err) {
                console.log('stop');
                return false
            }
            data.forEach((el, index) => {
                fs.stat(`${dirfather}/` + el, (err, data) => {
                    if (err) {
                        console.log('文件读取错误', err);
                        return false;
                    }
                    if (data.isDirectory()) {
                        //遍历文件夹
                        console.log('IsDirectory' + `${dirfather}/` + el);
                        //迭代
                        readdir(`${dirfather}/` + el)
                    } else {
                        console.log('Is File' + `${dirfather}/` + el);
                    }
                })
            })
        })
    }).listen(4900)
}

readDir(dirPath);

